package com.heima.wemedia.controller;

import com.heima.common.dtos.PageResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsPageReqDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import com.heima.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    /**
     * 根据条件查询文章数据
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news/page")
    public PageResult<WmNewsResultDTO> findByPage(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findByPage(dto);
    }

    /**
     * 文章保存,修改,提交审核
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/news/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        wmNewsService.submit(dto);
        return ResponseResult.ok();
    }

    /**
     * 根据主键id查询文章
     * @param wmNewsId
     * @return
     */
    @GetMapping("/api/v1/news/one/{id}")
    public ResponseResult<WmNewsResultDTO> getNewsById(@PathVariable(name = "id") Integer wmNewsId) {
        return ResponseResult.ok(wmNewsService.getNewsById(wmNewsId));
    }

    @PutMapping("api/v1/news/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        wmNewsService.downOrUp(dto);
        return ResponseResult.ok();
    }



}
